import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:${USER}
 * Date:${YEAR}-${MONTH}-${DAY}
 * ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int[] arr=new int[n*n];
        int[][] nums=new int[n][n];
        int k=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
               arr[k++]=nums[i][j]=in.nextInt();
            }
        }
        int count1=0;int count2=0;
        int q=in.nextInt();
        while(q--!=0){
            int x=in.nextInt();
            if(x==1){
                count1++;
            }else{
               count2++;
            }
        }
       if(count1%2!=0){
           fun1(arr,nums);
       }
        int k1=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                nums[i][j]=arr[k1++];
            }
        }
        if(count2%2!=0) {
            fun2(nums, n);
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(j!=n-1){
                    System.out.print(nums[i][j]+" ");
                }
                else{
                    System.out.print(nums[i][j]);
                }
            }
            System.out.println();
        }

    }

    public static void fun1(int[] arr,int[][] nums){
        int len=arr.length;
        for(int i=0;i<len/2;i++){
            int tmp=arr[i];
            arr[i]=arr[len-1-i];
            arr[len-1-i]=tmp;
        }

    }
    public static void fun2(int[][] nums,int n){
        for(int i=0;i<n/2;i++){
            for(int j=0;j<n;j++){
                int tmp=nums[i][j];
                nums[i][j]=nums[n-i-1][j];
                nums[n-i-1][j]=tmp;
            }
        }
    }
}